using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BlackJackSimulator
    {
    public partial class frmPlayerActionMatrix : Form
        {
        public frmPlayerActionMatrix()
            {
            InitializeComponent();
            SetUpGrid();
            }

 

        private PlayerMatrix clsPlayerMatrix = new PlayerMatrix();
        private void frmPlayerActionMatrix_Load(object sender,EventArgs e)
            {
            

            }

        private void SetUpGrid()
            {
            DataGridViewComboBoxCell cboAction = new DataGridViewComboBoxCell();
            cboAction.Items.Add("S");
            cboAction.Items.Add("H");
            cboAction.Items.Add("D");
            cboAction.Items.Add("P");
            cboAction.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
            
            foreach (DataGridViewColumn dgcPlayerMatrix in this.dgvPlayerMatrix.Columns)
                {
                if (dgcPlayerMatrix.GetType().FullName == "System.Windows.Forms.DataGridViewComboBoxColumn")
                    {
                    dgcPlayerMatrix.CellTemplate = cboAction;
                    
                    }
                
                dgcPlayerMatrix.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }

            
            }
 

        private void tsbLoadPlayerMatrix_Click(object sender,EventArgs e)
            {
            SetUpTables_2();
            }

        private void tsbSavePlayerMatrix_Click(object sender,EventArgs e)
            {
           
            }

        private void SetUpTables_2()
            {
      
            clsPlayerMatrix.SetUp_2();
            dgvPlayerMatrix.DataSource = clsPlayerMatrix.dtPlayerMatrix_2;

            }

        private void dgvPlayerMatrix_CellEndEdit(object sender,DataGridViewCellEventArgs e)
            {

            //if (e.RowIndex > 0 && e.ColumnIndex > 0)
            //    {
            //    string strAction;
            //    strAction = dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Value.ToString();
            //    switch (strAction)
            //        {
            //        case "H":
            //            dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightGreen;

            //            break;
            //        case "S":
            //            dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightCoral;

            //            break;
            //        case "P":
            //            dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightYellow;

            //            break;
            //        case "D":
            //            dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightBlue;

            //            break;
                  // }
              //  }
                
            }

        private void openToolStripButton_Click(object sender,EventArgs e)
            {
            
            
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                System.Data.DataTable dtLoad = new DataTable();
                dtLoad.ReadXml(openFileDialog1.FileName);
                dgvPlayerMatrix.DataSource = dtLoad;

                this.Text = "Player Matrix [" + openFileDialog1.FileName + "]";

                }
            }

        private void newToolStripButton_Click(object sender,EventArgs e)
            {
            dgvPlayerMatrix.DataSource = null;
            SetUpGrid();
            SetUpTables_2();
            this.Text = "Player Matrix [NEW]]";
            }

        private void saveToolStripButton_Click(object sender,EventArgs e)
            {
            saveFileDialog1.DefaultExt = ".xml";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                System.Data.DataTable dtSave = (System.Data.DataTable)dgvPlayerMatrix.DataSource;
                dtSave.WriteXml(saveFileDialog1.FileName,XmlWriteMode.WriteSchema);
                MessageBox.Show("Data Saved");
                this.Text = "Player Matrix [" + saveFileDialog1.FileName + "]";
                }

            }

        private void dgvPlayerMatrix_CellValueChanged(object sender,DataGridViewCellEventArgs e)
            {
           
            }

        private void dgvPlayerMatrix_CellPainting(object sender,DataGridViewCellPaintingEventArgs e)
            {
           
            }

        private void dgvPlayerMatrix_CellValidated(object sender,DataGridViewCellEventArgs e)
            {
          
            }

        private void dgvPlayerMatrix_CellFormatting(object sender,DataGridViewCellFormattingEventArgs e)
            {
            
            if (e.RowIndex >= 0 && e.ColumnIndex > 0)
                {
                string strAction;
                strAction = dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Value.ToString();
                switch (strAction)
                    {
                    case "H":
                        dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightGreen;

                        break;
                    case "S":
                        dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightCoral;

                        break;
                    case "P":
                        dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightYellow;

                        break;
                    case "D":
                        dgvPlayerMatrix[e.ColumnIndex,e.RowIndex].Style.BackColor = Color.LightBlue;

                        break;
                    }
                }
            }
        }
    }